package com.eece496.Server;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.eece496.Database.StudentGroups;

/**
 * Servlet implementation class ProfCOGSServlet
 */
public class ProfCOGSServlet extends MasterServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ProfCOGSServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Connect();
		String courseNumber = request.getParameter("courseNumber");
		String sectionNumber = request.getParameter("sectionNumber");
		String firstname = request.getParameter("firstname");
		String lastname = request.getParameter("lastname");
		
		String message = "Success";
		
		//Need to get the student group divisions
		StudentGroups StudentGroupDB = new StudentGroups();
		StudentGroupDB.Setup(connection);
		ArrayList<String> divisionList = new ArrayList<String>();
		try {
			divisionList = StudentGroupDB.GetDivisions(courseNumber, sectionNumber);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		System.out.println(divisionList.size());
		if(divisionList.size() == 0)
		{
			message = "Fail";
			request.setAttribute("courseNumber", courseNumber);
			request.setAttribute("sectionNumber", sectionNumber);
			request.setAttribute("firstname", firstname);
			request.setAttribute("lastname", lastname);
			request.setAttribute("message", message);
			
			request.getRequestDispatcher("/Professor/Professor-Add-COGS.jsp")
			.forward(request, response);
		}
		
	//	System.out.println(divisionList.get(0));
	//	System.out.println(divisionList.get(1));
		else{
		request.setAttribute("divisionList", divisionList);
		request.setAttribute("courseNumber", courseNumber);
		request.setAttribute("sectionNumber", sectionNumber);
		request.setAttribute("firstname", firstname);
		request.setAttribute("lastname", lastname);
		request.setAttribute("message", message);
		
		request.getRequestDispatcher("/Professor/Professor-Add-COGS.jsp")
		.forward(request, response);
		}
		
	}
}
